/**
 * Created by jian on 2017/12/30.
 */

var obj = getSearchObj()
$(".elder-name").html(obj.elderName)
$(".elder-card-id").html(obj.elderCard)

var chePing = {};

var testTopicItemIdArr = [];

var loginedUser = getLoginedUser();

var view = {
    data: chePing
};

var vue_vm = new Vue({
    el: '#vue_vm',
    data: view,
    methods: {
        radioClick(answerItem){
            for (var i = 0; i < testTopicItemIdArr.length; i++) {
                if (testTopicItemIdArr[i].testTopicItemId == answerItem.testTopicItemId) {//判断这道题是不是已经选过答案
                    testTopicItemIdArr.splice(i, 1);
                    break;
                }
            }
            testTopicItemIdArr.push(answerItem);
        }
    }
});

find_basic(path + '/testTopic/find',2 , function (res) {
    view.data = res.data[0];
    $('#vue_vm_list div').show();
});

function checkResult() {
    if (testTopicItemIdArr.length < view.data.testTopicItemForms.length) {
        alert("请完成所有题目")
        return;
    }
    doOpenWaiting('正在提交');
    console.log("======"+getData());

    save_basic_by_json(path + '/elderTestAnswerRecord/saveBatch',
        {"data": getData()},
        function (res) {
            var elderData = obj.elderId +"&elderName=" +obj.elderName + "&elderCard=" +obj.elderCard+"&testTopicId="+view.data.testTopicId+"&testTimesNumber="+obj.timesNumber;
            location.href ='2-2-1cheping-2-2.html?elderId='+elderData;
        });
    // for (var list in testTopicItemIdArr) {
    //     answerIdList.push(testTopicItemIdArr[list].answerId)
    //     testTopicItemIdList.push(testTopicItemIdArr[list].testTopicItemId)
    // }
}
function getData() {
    "use strict";
    var _testTopicItemIdArr = [];
    for (var i = 0; i < testTopicItemIdArr.length; i++) {
        testTopicItemIdArr[i].elderId = obj.elderId;
        testTopicItemIdArr[i].testTopicId = view.data.testTopicId;
        testTopicItemIdArr[i].testTimesNumber = obj.timesNumber;
        testTopicItemIdArr[i].staffId = loginedUser.staffId ;
        _testTopicItemIdArr.push(testTopicItemIdArr[i]);
    }
    var data = {
        "elderTestAnswerRecords": _testTopicItemIdArr,
        "testResultRecord": {
            "elderId": obj.elderId,
            "testTopicId": view.data.testTopicId,
            "staffId": "-1",//测试者id
            "testTimesNumber": parseInt(obj.timesNumber)//第几次测试
        }
    }
    return JSON.stringify(data);
}



